//
//  HMLandingView.swift
//  HMSlender
//
//  Created by 赵少朋赵少朋 on 17/1/17.
//  Copyright © 2017年 ITheima. All rights reserved.
//

import UIKit


class HMLandingView: UIView {

    
    var closure:(()->())?
    
     init(frame: CGRect, vcIndex: Int) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.init(r: 235, g: 235, b: 235, alpha: 1)
        
        
        switch vcIndex {
        case let i where i == 0:
            setupUI(iconImageName: "visitordiscover_feed_image_house", describeText: "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜")
            feedImage.isHidden = false
            setAnimation()
        case let i where i == 1:
            setupUI(iconImageName: "visitordiscover_image_message", describeText: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        case let i where i == 2:
            setupUI(iconImageName: "visitordiscover_image_message", describeText: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        case let i where i == 3:
            setupUI(iconImageName: "visitordiscover_image_profile", describeText: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        default:
            break
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setupUI(iconImageName:String, describeText:String) {
        //中间图片
        addSubview(iconImage)
        addSubview(feedImage)
        addSubview(maskImage)
        feedImage.isHidden = true
        
        //        feedImage.layer
        // MARK:登陆按钮
        addSubview(loginBtn)
        addSubview(describeLabel)
        addSubview(registerBtn)
        
        iconImage.image = UIImage(named: iconImageName)
        describeLabel.text = describeText
        
        iconImage.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        feedImage.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        maskImage.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        describeLabel.snp_makeConstraints { (make) in
            make.width.equalTo(230)
            make.top.equalTo(maskImage.snp_bottom).offset(16)
            make.centerX.equalTo(maskImage)
        }
        
        
        loginBtn.snp_makeConstraints { (make) in
            make.top.equalTo(describeLabel.snp_bottom).offset(16)
            make.left.equalTo(describeLabel)
            make.width.equalTo(100)
        }
        registerBtn.snp_makeConstraints { (make) in
            make.right.equalTo(describeLabel)
            make.top.equalTo(describeLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
        }
    }
    
    func setAnimation() {
        
        let animation = CABasicAnimation()
        //设置图片
        animation.keyPath = "transform.rotation"
        //旋转角度
        animation.toValue = M_PI * 2
        //动画时间
        animation.duration = 20
        // 重复次数
        animation.repeatCount = MAXFLOAT
        // 当切换控制器 或者程序退到后台 默认动画会被移除
        animation.isRemovedOnCompletion = false
        
        feedImage.layer.add(animation, forKey: nil)
    }
    
    private lazy var iconImage: UIImageView = {
    
        let img = UIImageView()
        img.image = UIImage(named: "visitordiscover_feed_image_house")
        img.sizeToFit()
        return img
    }()
//    visitordiscover_feed_image_smallicon
    private lazy var feedImage: UIImageView = {
        
        let img = UIImageView()
        img.image = UIImage(named: "visitordiscover_feed_image_smallicon")
        img.sizeToFit()
        return img
    }()
    //visitordiscover_feed_mask_smallicon
    private lazy var maskImage: UIImageView = {
    
        let img = UIImageView()
        img.image = UIImage(named:"visitordiscover_feed_mask_smallicon")
        img.sizeToFit()
        return img
    }()
    
    
    lazy var describeLabel: UILabel = {
    
        let label = UILabel()
        label.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        label.numberOfLines = 0
        label.font = UIFont.systemFont(ofSize: 14)
        label.textAlignment = .center
        return label
    }()
    
    private lazy var loginBtn: UIButton = {
        
        let btn = UIButton()
        btn.setTitle("登陆", for: UIControlState.normal)
        btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        btn.setTitleColor(themeColor, for: UIControlState.highlighted)
        btn.setBackgroundImage(UIImage(named:"common_button_white"), for: UIControlState.normal)
        btn.addTarget(self, action: #selector(registerBtnClick), for: UIControlEvents.touchUpInside)
        return btn
    }()
    
    lazy var registerBtn: UIButton = {
    
        let btn = UIButton()
        btn.setBackgroundImage(UIImage(named:"common_button_white"), for: UIControlState.normal)
        btn.setTitle("注册", for: UIControlState.normal)
        btn.setTitleColor(themeColor, for: UIControlState.highlighted)
        btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        btn.addTarget(self, action: #selector(registerBtnClick), for: UIControlEvents.touchUpInside)
        return btn
    }()
    
    //MARK: - 注册按钮点击事件
    func registerBtnClick() -> () {
        
        closure?()
    }
    
}












